package com.yanqu.road.server.timer.union;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.server.manger.activity.unionwar.UnionPhaseWarMgr;
import com.yanqu.road.server.manger.activity.unionwar.UnionWar;
import com.yanqu.road.server.manger.activity.unionwar.UnionWarActivityMgr;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.executor.GeneralTask;

import java.util.Map;
import java.util.Set;

/**
 * @author ：zfr
 * @date ：2021/8/3 16:54
 */
public class ActivityEndSyncUnionMemberTask extends GeneralTask {

    @Override
    public void doRun() {
        Map<Integer, ActivityInfo> activityInfoMap = UnionWarActivityMgr.getOpenActivityInfoMap();
        for (ActivityInfo activityInfo : activityInfoMap.values()) {
            //活动结束锁榜同步商会成员
            long nowTime2 = DateHelper.getCurrentSecond();
            if (nowTime2 >= activityInfo.getEndTime() && nowTime2 < activityInfo.getEndTime() + DateHelper.MINUTE_SECONDS * 480) {
                UnionWar unionWar = UnionPhaseWarMgr.getUnionWarMap().get(activityInfo.getActivityId());
                if (unionWar != null) {
                    getLOGGER().info("sync unionMember because activity end, activityId:{}", activityInfo.getActivityId());
                    //unionWar.syncAllUnionMember(2);
                    synchronized (unionWar.getCanGetRankRewardMemberMap()) {
                        Set<String> unionUidSet = unionWar.getCanGetRankRewardMemberMap().keySet();
                        for (String unionUid : unionUidSet) {
                            unionWar.syncCanGetRankRewardMemberMap(unionUid, 2);
                        }
                    }
                }
            }
        }
    }
}
